﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.popups.energy {
    import reprise.ui.*;
    import flash.events.*;
    import reprise.controls.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.popups.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;

    public class OutOfEnergyPopupMediator extends AbstractPopupMediator {

        public var languageModel:LanguageModel;
        private var _askButton:LabelButton;
        private var _okButton:LabelButton;

        private static const BUTTON_MARGIN:Number = 10;

        override public function onRegister():void{
            super.onRegister();
            var _local1:UIComponent = RepriseUtils.addComponent(this.view, "content");
            RepriseUtils.addComponent(this.view, "bear");
            RepriseUtils.addComponent(_local1, "boostIcon");
            var _local2:UIComponent = RepriseUtils.addComponent(this.view, "buttonContainer");
            RepriseUtils.validateComponent(_local2, this.onButtonContainer);
            if (!sessionModel.getRequestLimit(GameConstants.ENERGY)){
                this.addAskButton("global_button_askfriends", _local2);
                RepriseUtils.addLabel(_local1, "myriadProFontNormal copy", language.getTextByKey("boost_ask_text"));
            } else {
                RepriseUtils.addLabel(_local1, "myriadProFontNormal copy", language.getTextByKey("boost_ask_text2"));
            };
            addOkButton("global_buy", _local2);
            RepriseUtils.addLabel(_local1, "myriadProFontNormal headline", language.getTextByKey("boost_ask_headline"));
        }
        private function onButtonContainer(_arg1:UIComponent):void{
            var _local2:Number = 0;
            _local2 = (_local2 + (this._okButton) ? (this._okButton.borderBoxWidth + BUTTON_MARGIN) : 0);
            _local2 = (_local2 + (this._askButton) ? (this._askButton.borderBoxWidth + BUTTON_MARGIN) : 0);
            _arg1.setStyle("width", String(_local2));
        }
        private function addAskButton(_arg1:String, _arg2:UIComponent=null):void{
            var _local3:LabelButton = this.createAskButton(_arg1, _arg2);
            eventMap.mapListener(_local3, MouseEvent.CLICK, this.onAsk);
        }
        private function createAskButton(_arg1:String, _arg2:UIComponent=null):LabelButton{
            this._askButton = createButton(_arg2, "blueButton", _arg1, "myriadProFont");
            return (this._askButton);
        }
        override protected function createOkButton(_arg1:String, _arg2:UIComponent=null):LabelButton{
            this._okButton = createButton(_arg2, "greenButton", _arg1, "myriadProFont");
            return (this._okButton);
        }
        private function get view():OutOfEnergyPopupView{
            return ((viewComponent as OutOfEnergyPopupView));
        }
        override protected function onOk(_arg1:MouseEvent):void{
            dispatch(new Event(EventConstants.OPEN_BOOST_SHOP_POPUP));
            close();
        }
        private function onAsk(_arg1:MouseEvent):void{
            l(("onAsk: " + this.onAsk));
            var _local2:Object = {request_type:GameConstants.ENERGY, is_gift:false, entity_id:null};
            dispatch(new InfoEvent(EventConstants.SEND_GIFT_REQUEST, null, _local2));
            close();
        }

    }
}//package net.wooga.pets.views.popups.energy 
